﻿using Ant.Interface.Mef;

namespace Ant.BasicPlugIn.Data.Providers
{
    public delegate IDataServicesProvider CreateDataServicesProvider(string dataFolder, string connectionString);

    internal class DataServicesProviderFactory : IDataServicesProviderFactory
    {
        public IDataServicesProvider CreateProvider(DataServiceParameters parameters)
        {
            var factory = GetProviderFactory(parameters.Provider) ?? GetProviderFactory("SqlServer");

            return factory != null ? factory(parameters.DataFolder, parameters.ConnectionString) : null;
        }

        private static CreateDataServicesProvider GetProviderFactory(string providerName)
        {
            return (folder, connectionString) => MefFactory.GetInstance().Get<IDataServicesProvider>(providerName);
        }
    }
}